<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <a href="#/home">首页</a>
    <a href="#/about">关于我们</a>

    <hr>

    <div id="result"></div>

    <script>
        let result = document.querySelector('#result');

        //当页面 url 的 hash 值发生改变时会触发该事件
        window.addEventListener('hashchange', function () {
            //
            // console.log(window.location.hash);
            switch (location.hash) {
                case '#/home':
                    result.innerHTML = '<h2>首页</h2>'
                    break;

                case '#/about':
                    result.innerHTML = '<h2>关于我们</h2>'
                    break;

                default:
                    result.innerHTML = '欢迎您来到我的小破站'
                    break;
            }
        });
    </script>
</body>

</html>